/**
 * 
 */
package com.star.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName: ImageServletDao
 * @Description: TODO
 * @author starhq
 * @createtime 2014年10月28日 下午4:36:03
 * @email : jian.wang@shinsoft.net
 * @modify by TODO
 * @resaon
 * @edittime
 * @version 1.0
 * @copyright shinsoft
 */
public class ImageServletDao extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// private ImageDao imageDao;

	@Override
	public void init() throws ServletException {
		// this.imageDao = imageDao;
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String imageId = request.getParameter("id");

		if (imageId == null) {
			response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
			return;
		}

		Image image = null;
		// imageDAO.find(imageId);

		if (image == null) {
			response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
			return;
		}

		response.reset();
		response.setContentType(image.getContentType());
		response.setContentLength(image.getContent().length);

		response.getOutputStream().write(image.getContent());
	}
}
